package com.einmeer.hfbank.exception;

import com.einmeer.hfbank.vo.ResultVo;
import org.apache.ibatis.session.SqlSessionException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.FileNotFoundException;

/**
 * @author 芊嵛
 * @date 2024/1/11
 * 全局异常管理类
 */

@ControllerAdvice
public class GlobalAdvice {
    /**
     * 空指针异常
     * @return
     */
    @ExceptionHandler(NullPointerException.class)
    public String nullPointer(){
        //直接转发到static根下
        return "forward:null.html";
    }

    /**
     * 数组越界
     * @return
     */
    @ExceptionHandler(ArrayIndexOutOfBoundsException.class)
    public String arrayOutof(){
        //直接转发到static根下
        return "forward:out.html";
    }

    /**
     * 文件未找到
     * @return
     * 传入反射对象
     */
    @ExceptionHandler(FileNotFoundException.class)
    public String notFind(){
        //跳到/static/not.html
        return "forward:not.html";
    }
    @ExceptionHandler(SqlSessionException.class)
    @ResponseBody//返回json字符串
    public ResultVo mysqlException(){
        //跟前端约定好接口的标准
        return new ResultVo(3001,null,"数据更新异常 ");
    }
}
